﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace Utilities
{
    public class SerializationHelper
    {
        private static BinaryFormatter bf = new BinaryFormatter ();

        public static T FromBytes<T> (byte[] bytes)
        {
            MemoryStream ms = new MemoryStream(bytes);
            
            return (T)bf.Deserialize(ms);
        }

        public static byte[] ToBytes<T>(T obj)
        {
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, obj);
            return ms.GetBuffer();
        }
    
    }
}
